import 'package:HnXG/DIalog.dart';
import 'package:HnXG/pages/Login.dart';
import 'package:HnXG/pages/Pages/CachePage.dart';
import 'package:HnXG/pages/Pages/MaterialListPage.dart';
import 'package:HnXG/pages/Pages/NewWarehousePage.dart';
import 'package:HnXG/pages/Pages/ProductionPageLinePage.dart';
import 'package:HnXG/pages/Pages/QueuePage.dart';
import 'package:HnXG/pages/Pages/TaskViewPage.dart';




import 'package:flutter/material.dart';

class Tabs extends StatefulWidget{
  const Tabs({super.key});

  @override
  State<StatefulWidget> createState() => _Tabs();

}

class _Tabs extends State<Tabs> {
  int _currentIndex = 0;
  final List<Widget> _pages = const [
    NewWarehousePage(),
    CachePage(),
   ProductionPageLinePage(), 
        QueuePage(), 
     TaskViewPage(),    
     MaterialListPage(), 
    
 
         
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: WillPopScope(  // 新增防返回组件
        onWillPop: () async => false,  // 禁用返回手势
        child: _pages[_currentIndex],
      ),
      bottomNavigationBar: BottomNavigationBar(
        backgroundColor: Colors.white.withOpacity(1.0), // 添加不透明背景
        selectedItemColor: Colors.blue, // 选中状态颜色
        unselectedItemColor: Colors.grey, // 未选中状态颜色
        type: BottomNavigationBarType.fixed, // 固定导航栏样式
        currentIndex: _currentIndex,
        onTap: (index) async {  // 添加 async 关键字
          
          if (index == 6) {  // 检查是否点击了退出按钮{                 
            final result = await InfoDialog.show(context, "提示信息", "您确定要退出吗？");
            if (result == true) {  // 只有当用户点击确定时才跳转
              Navigator.pushReplacement(context, 
                MaterialPageRoute(builder: (context) => LoginPage()));     
            return;
          }
          }
   else{
setState(() => _currentIndex = index);
   }      
        },
        items: const [
          BottomNavigationBarItem(
            icon: Icon(Icons.warehouse),
            label: '新仓入库'
          ),
          BottomNavigationBarItem(
            icon: Icon(Icons.local_shipping),
            label: '小车缓存'
          ),
          BottomNavigationBarItem(
            icon: Icon(Icons.storage),
            label: '缓存取车'
          ),
                      BottomNavigationBarItem(
            icon: Icon(Icons.query_builder),
            label: '队列'
          ),
          BottomNavigationBarItem(
            icon: Icon(Icons.list_alt),
            label: '任务列表'
          ),
                BottomNavigationBarItem(
            icon: Icon(Icons.inventory_2),
            label: '物料清单'
          ),
          
    
          // BottomNavigationBarItem(
          //   icon: Icon(Icons.list_sharp),
          //   label: '退出'
          // ),

        ],
      ),
    );
  }
}